module.exports = class extends think.Model {
  // eslint-disable-next-line camelcase
  async list({ name, pageSize = 10, pageNum = 1, order = "id desc" }) {
    const where = {};

    if (name) {
      where.name = ["like", `%${name}%`];
    }

    const data = await this.where(where)
      .order(order)
      .page(pageNum, pageSize)
      .countSelect();
    return data;
  }

  async detail({ id }) {
    const data = await this.find(id);
    // eslint-disable-next-line camelcase
    const { user_id, id: metaId, ...meta } = await this.model("user_meta")
      .where({ user_id: id })
      .find();
    return { ...data, ...meta };
  }
};
